composetable: Allow removing sequences
authorMatthias Clasen <mclasen@redhat.com>
Wed, 7 Jul 2021 20:09:11 +0000 (16:09 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 14 Jul 2021 02:02:33 +0000 (22:02 -0400)
Interpret an empty string as value in the Compose
file to mean: Remove this sequence.

Tests included.

gtk/gtkcomposetable.c
testsuite/gtk/compose/include
testsuite/gtk/compose/included

index 449d63e34025e576bc67ddbd61602d16effce19a..e32f11f3d54edddd80e66e027fb00924e0f9b50d 100644 (file)
@@ -481,6 +481,10 @@ parser_read_file (GtkComposeParser *parser,
   g_free (contents);
 }
 
+/* Remove sequences that can be handled algorithmically,
+ * sequences with non-BMP keys, and sequences that produce
+ * empty strings.
+ */
 static void
 parser_remove_duplicates (GtkComposeParser *parser)
 {
@@ -498,6 +502,12 @@ parser_remove_duplicates (GtkComposeParser *parser)
       char buf[8] = { 0, };
       gboolean remove_sequence = FALSE;
 
+      if (value[0] == '\0')
+        {
+          remove_sequence = TRUE;
+          goto next;
+        }
+
       for (i = 0; i < MAX_COMPOSE_LEN + 1; i++)
         keysyms[i] = 0;
 
@@ -510,7 +520,10 @@ parser_remove_duplicates (GtkComposeParser *parser)
             break;
 
           if (codepoint > 0xffff)
-            remove_sequence = TRUE;
+            {
+              remove_sequence = TRUE;
+              goto next;
+            }
 
           n_compose++;
         }
@@ -522,6 +535,7 @@ parser_remove_duplicates (GtkComposeParser *parser)
             remove_sequence = TRUE;
         }
 
+next:
       if (remove_sequence)
         g_hash_table_iter_remove (&iter);
     }
index 10abadf446f6333396aa5ad7f8487a0cf143c3a0..f69d7a79e7c13b758335654ae972611c39e4e6c6 100644 (file)
@@ -1,3 +1,4 @@
 include "testsuite/gtk/compose/included"   # see if this works
 
-<Multi_key> <s> <s> <s> : "!"
+<Multi_key> <s> <s> <s> : "!" # replace this entry
+<Multi_key> <a> <a> <a> : ""  # remove this entry
index d5d3a68adccb8f6f954dd01d4a7957ae483c614d..77162b65633a367f0c282fb0ed196a2d7a7d1666 100644 (file)
@@ -1 +1,2 @@
 <Multi_key> <s> <s> <s> : "XO"
+<Multi_key> <a> <a> <a> : "Aaah!"